﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ValidationHelper.Validators
{
    public class CompareValidator : NumericValidator
    {
        #region Propriedades
        private CompareType comparisonType;

        public CompareType ComparisonType
        {
            get { return comparisonType; }
            set { comparisonType = value; }
        }

        private double numberToCompare;

        public double NumberToCompare
        {
            get { return numberToCompare; }
            set { numberToCompare = value; }
        } 
        #endregion

        #region Construtores
        public CompareValidator(string message, Type exceptionType, double numberToValidate, double numberToCompare, CompareType compareType)
            : base(message, exceptionType, numberToValidate)
        {
            ComparisonType = compareType;
            NumberToCompare = numberToCompare;
        } 
        #endregion

        #region Métodos
        protected override bool IsNotValid()
        {
            switch (ComparisonType)
            {
                case CompareType.Equal:
                    return !(NumberToValidate == NumberToCompare);
                case CompareType.Different:
                    return !(NumberToValidate != NumberToCompare);
                case CompareType.Less:
                    return !(NumberToValidate < NumberToCompare);
                case CompareType.LessOrEqual:
                    return !(NumberToValidate <= NumberToCompare);
                case CompareType.Greater:
                    return !(NumberToValidate > NumberToCompare);
                case CompareType.GreatherOrEqual:
                    return !(NumberToValidate >= NumberToCompare);
                default:
                    return true;
            }
        } 
        #endregion
    }
}
